<!DOCTYPE html>
<html>
  <head>
    <title>day16-demo1</title>
      <script src="../js/axios.min.js"></script>
  </head>
  <body>
    <div id="app">
      <input type="button" value="axios get()" onclick="get()"/>
      <input type="button" value="axios get1()" onclick="get1()"/>
      <input type="button" value="axios get2()" onclick="get2()"/>
      <input type="button" value="axios get3()" onclick="get3()"/>
      <input type="button" value="axios get4()" onclick="get4()"/>
      <input type="button" value="axios get5()" onclick="get5()"/>
    </div>
    <script>
        function get() {
            axios("http://127.0.0.1:5000/user/data")

        }
        function get1() {
            axios({
                method: "post",
                url:'http://127.0.0.1:5000/user/data',
                data:{
                    first:"first",
                    name:"xiaozhang",
                    age:18,
                    roles:[
                        1,2,3,4,5,6
                    ],
                    menu:[
                        {
                            id:1,
                            name:"用户操作"
                        },
                        {
                             id: 2,
                            name: "系统配置"
                        }

                    ]
                }
            })
        }
        function get2() {
            axios({
                method: "post",
                url:'/user/data',
                baseURL:"http://127.0.0.1:5000/",
                data:{
                    first:"first",
                    name:"xiaozhang",
                    age:18,
                    roles:[
                        1,2,3,4,5,6
                    ],
                    menu:[
                        {
                            id:1,
                            name:"用户操作"
                        },
                        {
                             id: 2,
                            name: "系统配置"
                        }

                    ]
                }
            })
        }
        function get3() {
            axios({
                method: "post",
                url:'/user/data',
                baseURL:"http://127.0.0.1:5000/",
                headers: {'token': 'besttest'},
                data:{
                    first:"first",
                    name:"xiaozhang",
                    age:18,
                    roles:[
                        1,2,3,4,5,6
                    ],
                    menu:[
                        {
                            id:1,
                            name:"用户操作"
                        },
                        {
                             id: 2,
                            name: "系统配置"
                        }

                    ]
                }
            })
        }
        function get4() {
            axios({
                method: "post",
                url:"",
                baseURL:"http://127.0.0.1:5000/",
                params: {
                  ID: 12345
        }
            })
        }
        function get5(){
          const form = new FormData()
          form.append("key","value")
          form.append("name","xiaowang")
          form.append("age",18)
          axios({
            url: "/user/data",
            baseURL: "http://127.0.0.1:5000/",
            method: "post",
            data: form
      }).then(response=>{
          console.log(response),
              console.log(response.data)
              const result=response.data
              alert(result)
              if(result.code===20000){
              alert("请求成功")
              }
              else {
                  alert("请求失败")
              }
          })
    }


    </script>
  </body>
</html>